//
//  ODConversationListViewController.swift
//  OdmIM
//
//  Created by Gao on 17/1/18.
//  Copyright © 2017年 OdmIM. All rights reserved.
//

import UIKit

class ODConversationListViewController: RCConversationListViewController {
    
    let conVC = RCConversationViewController()

    override func viewDidLoad() {
        super.viewDidLoad()

        // 设置融云信息
        setupRongInfo()

        
        
    }
}

// MARK: - 设置融云信息
fileprivate extension ODConversationListViewController {
    
    func setupRongInfo(){
        let appDelegate = UIApplication.shared.delegate as? AppDelegate
        appDelegate?.connectRongServer({
            // 设置需要显示哪些类型的会话
            self.setDisplayConversationTypes([
                RCConversationType.ConversationType_APPSERVICE.rawValue,
                RCConversationType.ConversationType_CHATROOM.rawValue,
                RCConversationType.ConversationType_CUSTOMERSERVICE.rawValue,
                RCConversationType.ConversationType_DISCUSSION.rawValue,
                RCConversationType.ConversationType_GROUP.rawValue,
                RCConversationType.ConversationType_PRIVATE.rawValue,
                RCConversationType.ConversationType_PUBLICSERVICE.rawValue,
                RCConversationType.ConversationType_SYSTEM.rawValue
                
                ])
            
            
            
            // 设置需要将哪些类型的会话在会话列表中聚合显示
            self.setCollectionConversationType([RCConversationType.ConversationType_DISCUSSION.rawValue,
                                                RCConversationType.ConversationType_GROUP.rawValue])
            
            // 如果需要，刷新列表
            self.refreshConversationTableViewIfNeeded()
            
        })
        
        // 融云空列表时，不显示横线列表
        conversationListTableView.tableFooterView = UIView()
        
        // 指示器状态
        showConnectingStatusOnNavigatorBar = true
        isShowNetworkIndicatorView = false
    }
    
}

// MARK: - 跳转会话画面
extension ODConversationListViewController {
    
    override func viewWillAppear(_ animated: Bool) {
    
        self.tabBarController?.tabBar.isHidden = false
    
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        
        let destVC = segue.destination as? RCConversationViewController
        
        destVC?.targetId = self.conVC.targetId
        // destVC?.userName = self.conVC.userName
        destVC?.conversationType = self.conVC.conversationType
        destVC?.title = conVC.title
        
        
        self.tabBarController?.tabBar.isHidden = true
        
    }
    
    override func onSelectedTableRow(_ conversationModelType: RCConversationModelType, conversationModel model: RCConversationModel!, at indexPath: IndexPath!) {
        
        conVC.targetId = model.targetId
        // conVC.userName = model.conversationTitle
        conVC.conversationType = RCConversationType.ConversationType_PRIVATE
        
        conVC.title = model.conversationTitle
        
        self.performSegue(withIdentifier: "tapOnCell", sender: self)

        
    }
}



